<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Canvans绘制直线</title>
    <style>
        canvas {
            display: block;
            margin: 10px auto 0;
            border: 1px solid orange;
        }
    </style>
</head>
<body>
    <canvas id="canvans" width="600" height="500">您的浏览器不支持canvans</canvas>
</body>
<script>
    const canvans = document.getElementById('canvans')
    const ctx = canvans.getContext('2d')

    ctx.beginPath()
    // 设置宽度
    ctx.lineWidth = 4
    // 设置颜色
    ctx.strokeStyle = 'red'
    ctx.moveTo(100,100)
    ctx.lineTo(300,300)
    ctx.lineTo(500,200)
    // 绘制
    ctx.stroke()
    ctx.closePath()
</script>
</html>